package app

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type Response struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

type Pager struct {
	Page      int `json:"page"`
	PageSize  int `json:"page_size"`
	TotalRows int `json:"total_rows"`
}

func Success(c *gin.Context, data interface{}) {
	if data == nil {
		data = make([]string, 0)
	}
	response := Response{Code: 0, Msg: "success", Data: data}
	c.JSON(http.StatusOK, response)
}

func Error(c *gin.Context, code int, msg string) {
	response := Response{Code: code, Msg: msg, Data: nil}
	c.JSON(http.StatusOK, response)
}
